package com.example.yilanchatserver.application.controller;

import com.example.yilanchatserver.business.freechat.service.ZhiPuService;
import com.example.yilanchatserver.business.freechat.service.dto.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/metah/zhipu")
public class ZhiPuController {

    @Resource
    private ZhiPuService zhiPuService;

    @GetMapping("/embedding")
    public ZhiPuEmbeddingDTO embedding() throws Exception {
        return zhiPuService.embedding();
    }

    @GetMapping("/knowledgeBase/get")
    public YiLanKnowledgeData getKnowledgeBase(@RequestParam String id) throws Exception {
        return zhiPuService.getKnowledgeBase(id);
    }

    @PostMapping("/knowledgeBase/capacity")
    public ZhiPuKnowledgeBaseCapacityVO knowledgeBaseCapacity() throws Exception {
        return zhiPuService.knowledgeBaseCapacity();
    }

    @PostMapping("/knowledge/create")
    public ZhiPuUploadDocumentVO knowledgeUploadDocument(@RequestParam String id, @RequestParam MultipartFile[] files, @RequestParam(required = false) Integer knowledge_type, @RequestParam(required = false) List<String> custom_separator, @RequestParam(required = false) Integer sentence_size, @RequestParam String product, @RequestParam String userId, @RequestParam String virtualRoleUk) throws Exception {
        ZhiPuUploadDocumentDTO zhiPuUploadDocumentDTO = new ZhiPuUploadDocumentDTO();
        zhiPuUploadDocumentDTO.setId(id);
        zhiPuUploadDocumentDTO.setFiles(files);
        zhiPuUploadDocumentDTO.setKnowledge_type(knowledge_type);
        zhiPuUploadDocumentDTO.setSentence_size(sentence_size);
        zhiPuUploadDocumentDTO.setCustom_separator(custom_separator);
        zhiPuUploadDocumentDTO.setProduct(product);
        zhiPuUploadDocumentDTO.setUserId(userId);
        zhiPuUploadDocumentDTO.setVirtualRoleUk(virtualRoleUk);
        return zhiPuService.knowledgeUploadDocument(zhiPuUploadDocumentDTO);
    }

    @GetMapping("/knowledge/reembedding")
    public void reEmbeddingknowledge(@RequestParam String id) throws Exception {
        zhiPuService.reEmbeddingknowledge(id);
    }

//    @PostMapping("/application/create")
//    public String createApplication(@RequestBody ZhiPuApplicationData zhiPuApplicationData) throws Exception {
//        return zhiPuService.createApplication(zhiPuApplicationData);
//    }

    @PostMapping("/application/list")
    public ZhiPuGetApplicationListVO getApplicationList(@RequestBody ZhiPuGetKnowledgeBaseListDTO zhiPuGetApplicationListDTO) throws Exception {
        return zhiPuService.getApplicationList(zhiPuGetApplicationListDTO);
    }

    @GetMapping("/application/get")
    public ZhiPuApplicationData getApplication(@RequestParam String id) throws Exception {
        return zhiPuService.getApplication(id);
    }

//    @GetMapping("/application/delete")
//    public void deleteApplication(String id) throws Exception {
//        zhiPuService.deleteApplication(id);
//    }

    @GetMapping("/document/slice")
    public ZhiPuSliceVO sliceDocument(ZhiPuSliceDTO zhiPuSliceDTO) throws Exception {
        return zhiPuService.sliceDocument(zhiPuSliceDTO);
    }

    @GetMapping("/knowledge/allOfUser")
    public List<YiLanDocumentData> knowledgeFromUser(@RequestParam String id) throws Exception {
        return zhiPuService.getAllKnowledgeDocumentList(id);
    }

    @GetMapping("/knowledgeBase/base")
    public String knowledgeBaseBase() throws Exception {
        return zhiPuService.findBase();
    }

    @GetMapping("/reset")
    public void reset(@RequestParam String userAccount) {
        zhiPuService.resetTalkList(userAccount);
    }

}
